package beans;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import javax.swing.ImageIcon;

public class StartInterface
{
	//属性声明
	int progress=0;//292 进度条的框
	int	picture = 1;//界面
	MusicPlayer music;
	GameFrame mainFrame;//主框架
	
	public StartInterface(GameFrame	mainFrame)
	{
		this.mainFrame=mainFrame;
		//初始化
		music = new MusicPlayer("植物大战僵尸/声音/Faster.wav");
		music.startPlayer();
		
	}
	
	void paintPicture(Graphics g)//画界面
	{
		if(picture==1)//加载界面
		{
			Image image = (new ImageIcon("植物大战僵尸/背景/游戏开始界面.jpg")).getImage();
			g.drawImage(image, 0, 0, null);//绘制图片API
			g.setColor(Color.RED);
			g.fillRect(252, 540, 292, 25); //绘制实心矩形API		
			g.setColor(Color.YELLOW);
			g.fillRect(252, 540, progress, 25); //绘制实心矩形API
			g.setFont(new Font("宋体", 0, 15));
			g.setColor(Color.GREEN);
			if(progress<=292)
			{
				g.drawString("游戏准备", 363, 557);
			}
			else
			{
				g.drawString("开始游戏", 363, 557);
			}
		}
		else if(picture==2)//菜单界面
		{
			Image image = (new ImageIcon("植物大战僵尸/背景/转化界面12.png")).getImage();
			g.drawImage(image, 0, 0, null);//绘制图片API
		}
		else if(picture==3)//关于我们
		{
			Image image = (new ImageIcon("植物大战僵尸/背景/关于我们.png")).getImage();
			g.drawImage(image, 0, 0, null);//绘制图片API
		}
		else if(picture==4)//打赏作者
		{
			Image image = (new ImageIcon("植物大战僵尸/背景/打赏作者.png")).getImage();
			g.drawImage(image, 0, 0, null);//绘制图片API
		}
		else if(picture==5)//排行榜
		{
			Image image = (new ImageIcon("植物大战僵尸/背景/排行榜.jpg")).getImage();
			g.drawImage(image, 0, 0, null);//绘制图片API
			
			g.setFont(new Font("宋体", 5, 40));
			g.setColor(Color.RED);
			g.drawString("英雄榜", 330, 120);
			
			g.setFont(new Font("宋体", 5, 30));
			g.setColor(Color.BLACK);
			
			
			User user1= new User("小波666","111",10);
			User user2= new User("小陈666","222",20);
			User user3= new User("小付666","333",30);
			
			
			g.drawString("排名", 100, 200);
			g.drawString("用户名", 300, 200);
			g.drawString("得分", 500, 200);
			
			g.drawString("1", 100, 300);
			g.drawString("2", 100, 400);
			g.drawString("3", 100, 500);
			
			g.drawString(user1.getUid(), 300, 300);
			g.drawString(user2.getUid(), 300, 400);
			g.drawString(user3.getUid(), 300, 500);
			
			g.drawString(String.valueOf(user1.getZombieDieMaxAmount()), 500, 300);
			g.drawString(String.valueOf(user2.getZombieDieMaxAmount()), 500, 400);
			g.drawString(String.valueOf(user3.getZombieDieMaxAmount()), 500, 500);
			
		}
	}

	private void moveProgress()//移动的进度条
	{
		if(progress<=292)
		{
			progress=progress+7;//进度条每一帧加7
		}
		if(progress==280) //卡他一下
		{
			try {
				Thread.sleep(800);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public void timeProcess()//定时执行
	{
		moveProgress();//进度条++
	}

	public void mouseClickActivity(int mx, int my)//鼠标点击后的几种情况(活动)
	{
		if(picture==1&&progress>292&&new Rectangle(252, 540, 292, 25).contains(mx, my))//加载界面
		{
			picture=2;
		}
		else if(picture==2&&new Rectangle(400,100,360,100).contains(mx, my))//开始游戏
		{	
			mainFrame.startPicture.music.stopPlayer();//停止开始界面的音乐
			mainFrame.startPicture=null;//开始界面改为0
			mainFrame.gamePicture = new GameInterface(mainFrame);//把主框架放入进入游戏界面，实例化
			mainFrame.gamePicture.prepare();///初始化游戏界面
		}
		else if(picture==2&&new Rectangle(400,214,340,80).contains(mx, my))//关于我们
		{
			picture=3;
		}
		else if(picture==3&&new Rectangle(0,0,800,600).contains(mx, my)) //关于我们返回界面二
		{
			picture=2;
		}
		else if(picture==2&&new Rectangle(407,295,300,75).contains(mx,my)) //打赏作者
		{
			picture=4;
		}
		else if(picture==4&&new Rectangle(0,0,800,600).contains(mx,my)) //打赏作者放回界面二
		{
			picture=2;
		}
		else if(picture==2&&new Rectangle(712,469,73,86).contains(mx, my))//退出游戏
		{
			System.exit(0);
		}
		else if(picture==2&&new Rectangle(95,330,160,170).contains(mx, my))//排行榜
		{
			picture=5;
		}
		else if(picture==5&&new Rectangle(0,0,800,600).contains(mx, my)) //排行榜返回界面二
		{
			picture=2;
		}
	}
	
	
}
